var actionSuffix = '.htm';//Spring DispatcherServlet校验的url-pattern
var action = '.htm';//Spring DispatcherServlet校验的url-pattern
var loginPage ='../main/login' + actionSuffix;
var dtUrl ='../warningMap/list' + actionSuffix;//舆情地图url
var popinionUrl ='../popinion/list' + actionSuffix;//预警处置url
var onlinepublishUrl = '../mbcommon/init' + actionSuffix;//网上发布rl
var ydUrl ='../review/review'+ actionSuffix;//评论引导url
var wmUrl ='../inventory/inventory'+ actionSuffix;//活跃网民url
var foreignMediaUrl = '../fmedia/fmedia'+ actionSuffix;//境外媒体url
var attentionMediaUrl = '../amedia/amedia'+ actionSuffix;//网媒关注url
var yuqingfxUrl='../yuqingfx/loadYuQingfx'+actionSuffix;//舆情分析url
//var wangluowzUrl='http://WWW.MSDDT.COM';//网络问政
var userListUrl = '../userMange/list'+actionSuffix;//用户管理Url
var overtime = '当前用户已超时';//会话超时提示
var logouUrl='../main/logout' + actionSuffix;//退出
var userMangerUrl='../userMange/list' + actionSuffix;
var udunMangerUrl='../udunMange/list' + actionSuffix;
var departmentMangerUrl='../deptManage/department' + actionSuffix;
var mBlogManagerUrl = '../mBlogManager/getMBlogAccountList' + actionSuffix;
var userInfoUrl='../userMange/userInfo' + actionSuffix;
var dutyManageUrl='../dutySchedule/dutyScheduleList' + actionSuffix;
var rAccountManagerUrl = '../review/selectAccount' + actionSuffix;
var inventoryM = '../inventory/getInventory' + actionSuffix + "?type=1";
var inventoryF = '../inventory/getInventory' + actionSuffix + "?type=2";
var rContentManagerUrl = '../review/getCommentList' + actionSuffix;
var smsUrl = '../sms/getMessageList' + actionSuffix;

//ajax Common Function
var ajaxCommFun = function(url, data, callback) {
    jQuery.ajax( {
        type: "post",
        url: url,
        data: data,
        dataType: 'json',
        success: callback
    });
};

//ajax Common Function add dataType
var ajaxCommFunWithDataType = function(url, data,dataType, callback) {
	jQuery.ajax({
		type : "post",
		url : url,
		data : data,
		dataType : dataType,
		success : callback
	});
};

//ajax Common Function With beforeSendFunc
var ajaxCommFunWithBeforeSend = function(url, data, callback, beforeSendFunc) {
    jQuery.ajax( {
        type: "post",
        url: url,
        data: data,
        dataType: 'json',
        success: callback,
        beforeSend: beforeSendFunc
    });
};

//获取path
var getContextPath = function() {
    var path = window.location.pathname;
    return path.substr(0, path.lastIndexOf('/') + 1);
};

//去除空格
String.prototype.Trim = function() { 
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

//loading
var getLoading = function(obj) {
    return '<div class="waiting fr" style="float:' + obj + ';">'
         + '<div class="wait_pic fl"><img src="../images/waiting.gif" width="16px" height="16px"/></div>'
         + '<div class="wds fl">正在加载，请稍候...</div>'
         + '<div class="cl"></div>'
         + '</div>';
};

//判断用户超时
var overtimeFunc = function(data) {
    return data.overtime == 0 ? true : false;
};

//sharefun2013-12-10  获取checkbox参数形式的值
var getCheckboxValueByName = function(dagouclass,parentSelector) {
    var chk_value = [];
    var parent="";
    if(parentSelector!=null){
        parent="#"+parentSelector+" ";
    }
    jQuery(parent+"." + dagouclass).each(function() {
        if(jQuery(this).find(".ckbx").val() != 0) {
            chk_value.push(jQuery(this).find(".ckbx").val());
        }
    });
    return chk_value.length == 0 ? '0' : chk_value + "";
};

//菜单跳转
var goUrl = function(objUrl) {
    window.location.href = objUrl;
};

//sharefun2068 2014-01-02  毫秒转日期
var timesToDateFormat = function(times) {
    var c = new Date(Number(times));
    var y = c.getFullYear();
    var m = c.getMonth() + 1;//0-11代表月份,0是一月
    var mstr = m.toString();
    if (mstr.length < 2) {//不足两位加零
        mstr = "0" + mstr;
    }
    var d = c.getDate();
    var dstr = d.toString();//不足两位加零
    if (dstr.length < 2) {
        dstr = "0" + dstr;
    }
    var hh=c.getHours();
    var hhstr = hh.toString();//不足两位加零
    if (hhstr.length < 2) {
        hhstr = "0" + hhstr;
    }  
    var minute=c.getMinutes();
    var minutestr = minute.toString();//不足两位加零
    if (minutestr.length < 2) {
        minutestr = "0" + minutestr;
    }
    var second=c.getSeconds();
    var secondstr = second.toString();//不足两位加零
    if (secondstr.length < 2) {
        secondstr = "0" + secondstr;
    }
    
    return  y + "年" + mstr+"月"+dstr+"日 "+hhstr+":"+minutestr+":"+secondstr;
}

jQuery(function() {
    jQuery('#password1,#password2,#password3').bind({
        focus: function() {
            if (this.value == this.defaultValue) {
                this.value = "";
            }
        },
        blur: function() {
            if (this.value == "") {
                this.value = this.defaultValue;
            }
        }
    });
})

var layers;
var updatePassword = function(){
    layers = jQuery.layer({
        type: 1,
        title: "修改用户密码",
        border : [5, 0.5, '#666', true],
        offset: ['200px', ''],
        move: ['.xubox_title' , true],
        area: ['290px', '250px'],
        page: {dom: '#updatePass'}
    });
}

var updatepass = function(){
    var oldPass = jQuery("#password1").val();
    var newPass = jQuery("#password2").val();
    var newPass1 = jQuery("#password3").val();
    if(oldPass == "请输入当前密码"){
        layer.alert("请输入当前密码！");
        return false;
    }
    if(newPass == "请输入新密码"){
        layer.alert("请输入新密码！");
        return false;
    }
    if(newPass != newPass1){
        layer.alert("两次输入的密码不一致！");
        return false;
    }
    var fun = function(msg){
        if(msg.result == "error"){
            layer.alert("当前密码错误！");
        }else if(msg.result == "success"){
            layer.msg("修改成功！", 2, 10);
            location.href = globePath + "/main/login.htm";
        }else{
            layer.alert(msg.result);
        }
    }
    ajaxCommFun(globePath + "/main/updatePassword.htm", "oldPass=" + oldPass + "&newPass=" + newPass, fun);
}
var checkNum = function(num){
     var pattern = /^[1-9]\d*$/;
     if(num.value==""){
         num.focus();
         return ;
     }
     if (!pattern.test(num.value)){
         layer.alert("请输入正整数!");
         num.value = num.value.replace(/[\D]/g,"");
     }
     var a = num.value;
    //数字开头不能为0。
    for(var i=0;i<num.value.length;i++){
        if(a.length>0&&a.substring(0,1)=="0"){
           a = a.substring(1,a.length);
        }else{
           break;
        }
    }
    num.focus();
    num.value = a.replace(/[\D]/g,"");
}

//去除空字符函数 sharefun2068 2014-01-15 add
String.prototype.trim=function(){
  return this.replace(/(^\s*)|(\s*$)/g, "");
};

String.prototype.ltrim=function(){
  return this.replace(/(^\s*)/g,"");
};
String.prototype.rtrim=function(){
   return this.replace(/(\s*$)/g,"");
 };
 
 //替换所有的回车换行
var TransferString=function(content)
{
    var string = content;
    try{
    if(string!=null){
    string=string.replace(/\r\n/g,"<BR>")
    string=string.replace(/\n/g,"<BR>");
    }
    }catch(e) {
            alert(e.message);
    }
    return string;
}

//url验证
function isURL(url) {
  //var re= new RegExp("(http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&amp;*+?:_/=<>]*)?", "gi");
   var strRegex = "^((https|http|ftp|rtsp|mms)?://)"  
       + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"   
       + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184  
       + "|" // 允许IP和DOMAIN（域名） 
       + "([0-9a-z_!~*'()-]+\.)*" // 域名- www.  
       + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名  
       + "[a-z]{2,6})" // first level domain- .com or .museum  
       + "(:[0-9]{1,4})?" // 端口- :80  
       + "((/?)|" // a slash isn't required if there is no file name  
       + "(/[a-zA-Z0-9_!~*'().;?:@&=+$,%#-]+)+/?)$";   
       var re=new RegExp(strRegex);         
    if (re.test(url)) {
                return true;
            } else {
                 return false;
            }
  }

//验证手机号
var isMobile = function(mobile) {
    var pattern=/(^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$)|(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
    var re=new RegExp(pattern);  
    if(re.test(mobile)) { 
              return true; 
      }else{ 
               return false; 
     }
}

//转换成数组，去掉重复，再组合好。sharefun2068 2014-03-25 
function removeDuplicate(str,fuhaoStr) {
    if(str==null||str==""){
        return str;
    }
     var ary = str.split(fuhaoStr);
    // 去重的算法 
        var json = {};
        for (var i = 0; i < ary.length; i++) {
            if (ary[i] != "") {
                json["a" + ary[i]] = ary[i];
            }
        }
    // 查看结果 
        var str2 = "";
        for (var key in json) {
            str2 += fuhaoStr + json[key];
        }
        var s = str2.toString();
    //去掉第一个逗号 
        if (s.substr(0, 1) == fuhaoStr) {
            s = s.substr(1);
        }
        return s;
    } 

//---------------------------------------------------  
// 日期格式化  
// 格式 YYYY/yyyy/YY/yy 表示年份  
// MM/M 月份  
// W/w 星期  
// dd/DD/d/D 日期  
// hh/HH/h/H 时间  
// mm/m 分钟  
// ss/SS/s/S 秒  
Date.prototype.Format = function(formatStr)   
{   
    var str = formatStr;   
    var Week = ['日','一','二','三','四','五','六'];  
    str=str.replace(/yyyy|YYYY/,this.getFullYear());   
    str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));   
    str=str.replace(/MM/,this.getMonth()>9?this.getMonth().toString():'0' + (this.getMonth()+1));   
    str=str.replace(/M/g,(this.getMonth()+1));   
    str=str.replace(/w|W/g,Week[this.getDay()]);   
    str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());   
    str=str.replace(/d|D/g,this.getDate());   
    str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());   
    str=str.replace(/h|H/g,this.getHours());   
    str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());   
    str=str.replace(/m/g,this.getMinutes());   
    str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());   
    str=str.replace(/s|S/g,this.getSeconds());   
    return str;   
};

var getCurrDate = function(){
	var date = new Date();
    var m = date.getMonth() + 1;//0-11代表月份,0是一月
    var d = date.getDate();
    
    var mstr = m.toString();
    if (mstr.length < 2) {//不足两位加零
        mstr = "0" + mstr;
    }
    var dstr = d.toString();
    if (dstr.length < 2) {//不足两位加零
        dstr = "0" + dstr;
    }
	return date.getFullYear()+"-"+mstr+"-"+dstr;
};

var getFirstDateOfCurrMonth = function(){
	var date = new Date();
    var m = date.getMonth() + 1;//0-11代表月份,0是一月
    
    var mstr = m.toString();
    if (mstr.length < 2) {//不足两位加零
        mstr = "0" + mstr;
    }
	return date.getFullYear()+"-"+mstr+"-01";
};



var win = win || {
	isIE6 : !!window.ActiveXObject && !window.XMLHttpRequest,
	STATUS_TYPE : {
		mark : "mark",
		alert : "alert",
		short : "short",
		confirm : "confirm",
		none : "none"
	}
};
win.status = win.STATUS_TYPE.none;
win.showMark = function() {
	win.status = win.STATUS_TYPE.mark;
	$("#win_mark").show();
};
win.hideMark = function() {
	win.status = win.STATUS_TYPE.none;
	$("#win_mark").hide();
};
win.msg = win.msg || {};
win.msg.short = function(msg, arg1, arg2, arg3) {
	win.status = win.STATUS_TYPE.short;

	var callback = (typeof arg1 == "function") ? arg1 : undefined;
	var icon = (typeof arg1 == "string") ? arg1 : ((typeof arg2 == "string") ? arg2 : "Ok01");
	var delay = (typeof arg1 == "number") ? arg1 : ((typeof arg2 == "number") ? arg2 : arg3);

	$('#win_msg_short_content').text(msg);// show massage
	$('#win_msg_short_icon').removeClass();// clear last short
	$('#win_msg_short_icon').addClass("boxshort " + icon);// show icon

	// center
	var shapepropro = util.calculator.shapepro($("#win_msg_short"));
	$('#win_msg_short').css("margin-top", "-" + 200 + "px");
	$('#win_msg_short').css("margin-left", "-" + (shapepropro.val.width / 2) + "px");

	$('div[win=msg_short]').show();// show short massage

	// event
	var isInvoked = false;
	var shortfun = function() {
		if (callback && !isInvoked) {
			isInvoked = true;
			callback();
		}
	};
	var closefun = function() {
		$('div[win=msg_short]').fadeOut();// slow hide
		win.status = win.STATUS_TYPE.none;
	}

	// trigger
	var timerid = setTimeout(function() {
		shortfun();
		closefun();
	}, delay || 1500);
	$('#win_msg_short,#win_msg_short_bkg').click(function() {
		clearTimeout(timerid);
		shortfun();
		closefun();
	});
};
win.msg.short.close = function() {
	$('div[win=msg_short]').click();
};
win.popupBox = {
	open : function(url, config) {
		$('div[win=win_popupbox]').show();
		$('#win_popupbox').css("margin-top", "-" + (config.top ? config.top : (config.height / 5 * 3)) + "px");
		$('#win_popupbox').css("margin-left", "-" + (config.width / 2) + "px");
		$('#win_popupbox').html('<div><iframe frameborder="0" allowTransparency="true" scrolling="no" style="_border:none;width:' + config.width + 'px;height:' + config.height + 'px;" src="' + url + '"/></div>');
	},
	close : function() {
		$('div[win=win_popupbox]').hide();
		$('#win_popupbox').children().remove();
	}
};
function confirmAlert(msg) {
	$('#msgid2').text(msg);
	$('#light2').css("display", "block");
	$('#fade2').css("display", "block");

	// center
	var shapepropro = util.calculator.shapepro($("#light2"));
	$('#light2').css("margin-top", "-" + 200 + "px");
	$('#light2').css("margin-left", "-" + (shapepropro.val.width / 2) + "px");

}

function confirmCancel() {
	document.getElementById('light2').style.display = 'none';
	document.getElementById('fade2').style.display = 'none';
	win.status = win.STATUS_TYPE.none;
}

var confirms = function(args) {// msgs, data, success, erorr
	win.status = win.STATUS_TYPE.confirm;
	// 弹出框
	var div1 = '<div class="boxBtn mr20" id="confirmsid" >确定</div><div class="boxBtn" id="confirmCancel">取消</div>';
	document.getElementById('confirmdiv').innerHTML = div1;

	confirmAlert(args.msgs);

	// 数据
	args.data = args.data || {};

	// 确定
	$("#confirmsid").click(args.data, function(e) {
		if (args.success)
			args.success(e.data);
		document.getElementById('confirmdiv').innerHTML = "";
		confirmCancel();
	});
	// 取消
	$("#confirmCancel").click(args.data, function(e) {
		if (args.erorr)
			args.erorr(e.data);
		document.getElementById('confirmdiv').innerHTML = "";
		confirmCancel();
	});
}

function alertMsg(msg, callback) {
	win.status = win.STATUS_TYPE.alert;
	$('#msgid').text(msg);
	$('#light').css("display", "block");
	$('#fade').css("display", "block");

	// center
	var shapepropro = util.calculator.shapepro($("#light"));
	$('#light').css("margin-top", "-" + 200 + "px");
	$('#light').css("margin-left", "-" + (shapepropro.val.width / 2) + "px");

	// 确定
	$("#alertid").unbind('click').click(function(e) {
		if (callback)
			callback(e);
		document.getElementById('light').style.display = 'none';
		document.getElementById('fade').style.display = 'none';
		win.status = win.STATUS_TYPE.none;
	});
}
